<% layout('/layouts/default.html', {title: '商品管理', libs: ['validate','dataGrid','fileupload']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header with-border">
			<div class="box-title">
				<i class="fa icon-note"></i> ${text(goods.isNewRecord ? '新增商品' : '编辑商品')}
			</div>
			<div class="box-tools pull-right">
				<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
			</div>
		</div>
		<#form:form id="inputForm" model="${goods}" action="${ctx}/storage/goods/save" method="post" class="form-horizontal">
		<div class="box-body">
			<div class="form-unit">${text('基本信息')}</div>
			<#form:hidden path="id"/>
			<div class="row">
				<div class="col-xs-12">
					<div class="form-group">
						<label class="control-label col-sm-2">
							<span class="required ">*</span> ${text('商品主图')}：
						</label>
						<div class="col-sm-10">
							<div style="color:red;margin-bottom:10px;">
								建议尺寸：800PX * 800PX
							</div>
							<#form:hidden class="form-control" id="thumbnail" name="thumbnail" path="thumbnail"/>
							<#form:fileupload id="imagethumbnail" uploadType="image" returnPath="true" filePathInputId="thumbnail" class="form-control" readonly="false" maxUploadNum="1" imageMaxWidth="1125" imageMaxHeight="1125"/>
						</div>
					</div>
				</div>
			</div>
			<div class="row">
				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
							<span class="required ">*</span> ${text('品牌店铺')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-8">
							<#form:select path="brandId" readonly="${!goods.isNewRecord}" class="form-control" items="${brands}" itemLabel="name" itemValue="id" blankOption="true" blankOptionLabel="请选择"/>
						</div>
					</div>
				</div>
				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
							<span class="required ">*</span> ${text('商品分类')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-8">
							<#form:select path="cateId" class="form-control" items="${categoies}" itemLabel="name" itemValue="id" blankOption="true" blankOptionLabel="请选择"/>
						</div>
					</div>
				</div>
			</div>
			<div class="row">
				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
							<span class="required ">*</span> ${text('平台编号')}：<i class="fa icon-question hide"></i>
						</label>
						<div class="col-sm-8">
							<#form:input path="platform" maxlength="255" class="form-control required"/>
						</div>
					</div>
				</div>
				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
							<span class="required ">*</span> ${text('款号')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-8">
							<#form:input path="code" maxlength="255" class="form-control required"/>
						</div>
					</div>
				</div>
			</div>
			<div class="row">
				<div class="col-xs-12">
					<div class="form-group">
						<label class="control-label col-sm-2">
							<span class="required ">*</span> ${text('商品名称')}：<i class="fa icon-question hide"></i>
						</label>
						<div class="col-sm-10">
							<#form:input path="name" maxlength="255" class="form-control required"/>
						</div>
					</div>
				</div>
			</div>
			<div class="row">
				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
							${text('产品年份')}：<i class="fa icon-question hide"></i>
						</label>
						<div class="col-sm-8">
							<#form:input path="year" maxlength="255" class="form-control"/>
						</div>
					</div>
				</div>
				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
							${text('产品季节')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-8">
							<#form:input path="season" maxlength="255" class="form-control"/>
						</div>
					</div>
				</div>
			</div>
			<div class="row">
				<div class="col-xs-12">
					<div class="form-group">
						<label class="control-label col-sm-2">
							${text('商品大类')}：<i class="fa icon-question hide"></i>
						</label>
						<div class="col-sm-10">
							<#form:input path="category" maxlength="255" class="form-control"/>
						</div>
					</div>
				</div>
			</div>
			<div class="row">
				<div class="col-xs-12">
					<div class="form-group">
						<label class="control-label col-sm-2"><span class="required ">*</span> ${text('素材')}：</label>
						<div class="col-sm-10">
							<div style="color:red;margin-bottom:10px;">
								建议尺寸：1125PX * 1125PX，至少4张以上
							</div>
							<#form:hidden class="form-control" id="picture" name="picture" path="picture"/>
							<#form:fileupload id="imagepicture" uploadType="image" returnPath="true" filePathInputId="picture" class="form-control" readonly="false" maxUploadNum="255" imageMaxWidth="1125" imageMaxHeight="1125"/>
						</div>
					</div>
				</div>
			</div>
			<div class="row">
				<div class="col-xs-12">
					<div class="form-group">
						<label class="control-label col-sm-2">
							${text('产地')}：<i class="fa icon-question hide"></i>
						</label>
						<div class="col-sm-10">
							<#form:input path="place" maxlength="255" class="form-control required"/>
						</div>
					</div>
				</div>
			</div>
			<div class="row">
				<div class="col-xs-12">
					<div class="form-group">
						<label class="control-label col-sm-2">
							${text('材质')}：<i class="fa icon-question hide"></i>
						</label>
						<div class="col-sm-10">
							<#form:input path="material" maxlength="255" class="form-control required"/>
						</div>
					</div>
				</div>
			</div>
			<h4 class="form-unit">${text('商品规格表')}</h4>
			<div class="ml10 mr10">
				<table id="goodsSpecDataGrid"></table>
				<a href="javascript:void(0);" id="goodsSpecDataGridAddRowBtn" class="btn btn-primary btn-sm mt10 mb10"><i class="fa fa-plus"></i> ${text('增行')}</a>
			</div>
		</div>
		<div class="box-footer">
			<div class="row">
				<div class="col-sm-offset-2 col-sm-10">
					<button type="submit" class="btn btn-sm btn-primary" id="btnSubmit"><i class="fa fa-check"></i> ${text('保 存')}</button>&nbsp;
					<button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
				</div>
			</div>
		</div>
	</#form:form>
</div>
</div>
<% } %>
<script>
	//初始化商品规格表DataGrid对象
	$("#goodsSpecDataGrid").dataGrid({
		data: ${toJson(goods.goodsSpecList)},
		datatype: "local", // 设置本地数据
		autoGridHeight: function(){return 'auto'}, // 设置自动高度

		// 设置数据表格列
		columnModel: [
			{header:'主键', name:'id', editable:true, hidden:true},
			{header:'${text("状态")}', name:'status', editable:true, hidden:true},
			{header:'${text("条形码")}', name:'code', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'255', 'class':'form-control required'}},
			{header:'${text("尺码")}', name:'name', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'255', 'class':'form-control required'}},
			{header:'${text("颜色")}', name:'color', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'255', 'class':'form-control'}},
			{header:'${text("吊牌价")}', name:'price', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control required number'}},
			{header:'${text("普通会员价")}', name:'memberPrice', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control required number'}},
			{header:'${text("VIP会员价")}', name:'vipPrice', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control required number'}},
			{header:'${text("代购费")}', name:'agentPrice', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control required number'}},
			{header:'${text("备注")}', name:'remarks', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control'}},
			{header:'${text("操作")}', name:'actions', width:80, sortable:false, fixed:true, formatter: function(val, obj, row, act){
				var actions = [];
				actions.push('<a href="javascript:void(0);" onclick="js.confirm(\'${text("你确认要删除这条数据吗？")}\', function(){$(\'#goodsSpecDataGrid\').dataGrid(\'delRowData\',\''+obj.rowId+'\')});return false;"><i class="fa fa-trash-o"></i>删除</a>&nbsp;');
				return actions.join('');
			}, editoptions: {defaultValue: 'new'}}
		],

		// 编辑表格参数
		editGrid: true,				// 是否是编辑表格
		editGridInitRowNum: 1,		// 编辑表格的初始化新增行数
		editGridAddRowBtn: $('#goodsSpecDataGridAddRowBtn'),	// 子表增行按钮
		editGridAddRowInitData: {id: '', status: Global.STATUS_NORMAL},	// 新增行的时候初始化的数据

		// 编辑表格的提交数据参数
		editGridInputFormListName: 'goodsSpecList', // 提交的数据列表名
		editGridInputFormListAttrs: 'status,id,goodsId.id,sort,code,name,color,price,memberPrice,vipPrice,agentPrice,remarks,createBy,createDate,updateBy,updateDate,', // 提交数据列表的属性字段
	});
</script>
<script>
	$("#inputForm").validate({
		submitHandler: function(form){
			js.ajaxSubmitForm($(form), function(data){
				js.showMessage(data.message);
				if(data.result == Global.TRUE){
					js.closeCurrentTabPage(function(contentWindow){
						contentWindow.page();
					});
				}
			}, "json");
		}
	});
</script>